home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 April: Mac OS SDK / Dev.CD Apr 96 SDK / Dev.CD Apr 96 SDK1.toast / Development Kits (Disc 1) / OpenDoc Development Framework / ODFDev / ODF / Examples / Draw / Sources / DrwPrmse.cpp < prev    next >
Encoding:
Text File  |  1995-11-08  |  6.1 KB  |  236 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                DrwPrmse.cpp
  4. //    Release Version:    $ 1.0d11 $
  5. //
  6. //    Copyright:    © 1995 by Apple Computer, Inc., all rights reserved.
  7. //
  8. //========================================================================================
  9.  
  10. #include "ODFDraw.hpp"
  11.  
  12. #ifndef DRWPRMSE_H
  13. #include "DrwPrmse.h"
  14. #endif
  15.  
  16. #ifndef DRAWPRXY_H
  17. #include "DrawPrxy.h"
  18. #endif
  19.  
  20. #ifndef DRAWPART_H
  21. #include "DrawPart.h"
  22. #endif
  23.  
  24. #ifndef DRAWSEL_H
  25. #include "DrawSel.h"
  26. #endif
  27.  
  28. #ifndef BASESHP_H
  29. #include "BaseShp.h"
  30. #endif
  31.  
  32. #ifndef BOUNDSHP_H
  33. #include "BoundShp.h"
  34. #endif
  35.  
  36. #ifndef LINESHP_H
  37. #include "LineShp.h"
  38. #endif
  39.  
  40. #ifndef OVALSHP_H
  41. #include "OvalShp.h"
  42. #endif
  43.  
  44. #ifndef RECTSHP_H
  45. #include "RectShp.h"
  46. #endif
  47.  
  48. #ifndef RRECTSHP_H
  49. #include "RRectShp.h"
  50. #endif
  51.  
  52. #ifndef TEXTSHP_H
  53. #include "TextShp.h"
  54. #endif
  55.  
  56. #ifndef UTILS_H
  57. #include "Utils.h"
  58. #endif
  59.  
  60. // ----- OS Layer -----
  61.  
  62. #ifndef FWSUSINK_H
  63. #include "FWSUSink.h"
  64. #endif
  65.  
  66. #ifndef FWORDCOL_H
  67. #include "FWOrdCol.h"
  68. #endif
  69.  
  70. #ifndef FWPICTUR_H
  71. #include "FWPictur.h"
  72. #endif
  73.  
  74. // ----- Foundation Includes -----
  75.  
  76. #ifndef FWSTREAM_H
  77. #include "FWStream.h"
  78. #endif
  79.  
  80. #ifndef FWPRISTR_H
  81. #include "FWPriStr.h"
  82. #endif
  83.  
  84. #ifndef FWMEMMGR_H
  85. #include "FWMemMgr.h"
  86. #endif
  87.  
  88. #ifndef FWMEMHLP_H
  89. #include "FWMemHlp.h"
  90. #endif
  91.  
  92. // ----- OpenDoc Includes -----
  93.  
  94. #ifndef SOM_Module_OpenDoc_StdProps_defined
  95. #include <StdProps.xh>
  96. #endif
  97.  
  98. //========================================================================================
  99. // RunTime Info
  100. //========================================================================================
  101.  
  102. #ifdef FW_BUILD_MAC
  103. #pragma segment odfdraw
  104. #endif
  105.  
  106. //========================================================================================
  107. //    class CDrawPromise
  108. //========================================================================================
  109.  
  110. //----------------------------------------------------------------------------------------
  111. //    CDrawPromise::CDrawPromise
  112. //----------------------------------------------------------------------------------------
  113.  
  114. CDrawPromise::CDrawPromise(Environment*ev, ODUpdateID updateID, FW_EStorageKinds storageKind, CDrawPart* part, FW_CFrame* scopeFrame, CDrawSelection* selection) :
  115.     FW_CPromise(ev, updateID, storageKind, part, scopeFrame),
  116.     fDrawSelection(selection),
  117.     fCollection(NULL)
  118. {
  119.     fDrawSelection->GetDragRect(fSelectionRect);
  120.     
  121.     fCollection = new FW_CPrivOrderedCollection;
  122.     
  123.     FW_COrderedCollectionIterator ite(part->GetShapeList());
  124.     for (CBaseShape *shape = (CBaseShape*)ite.First(); ite.IsNotComplete(); shape = (CBaseShape*)ite.Next())
  125.     {
  126.         if (shape->IsSelectedShape())
  127.         {
  128.             shape->Promised(storageKind, TRUE);
  129.             fCollection->AddLast(shape);
  130.         }
  131.     }
  132. }
  133.  
  134. //----------------------------------------------------------------------------------------
  135. //    CDrawPromise::~CDrawPromise
  136. //----------------------------------------------------------------------------------------
  137.  
  138. CDrawPromise::~CDrawPromise()
  139. {
  140.     if (fCollection)
  141.     {
  142.         Environment* ev = somGetGlobalEnvironment();
  143.         
  144.         FW_COrderedCollectionIterator ite(fCollection);
  145.         for (CBaseShape *shape = (CBaseShape*)ite.First(); ite.IsNotComplete(); shape = (CBaseShape*)ite.Next())
  146.         {
  147.             shape->Promised(GetStorageKind(ev), FALSE);
  148.         }
  149.  
  150.         delete fCollection;        // Will call RemoveAll
  151.         fCollection = NULL;
  152.     }
  153. }
  154.  
  155. //----------------------------------------------------------------------------------------
  156. //    CDrawPromise::PromisePropertiesAndValues
  157. //----------------------------------------------------------------------------------------
  158.  
  159. void CDrawPromise::PromisePropertiesAndValues(Environment *ev, ODStorageUnit* storageUnit)
  160. {
  161.     FW_CPromise::PromisePropertiesAndValues(ev, storageUnit);    // kODPropContents with the part kind value
  162.     
  163. #ifdef FW_BUILD_MAC
  164.     this->Promise(ev, storageUnit, kODPropContents, FW_CPart::gMacPICTDataType);
  165. #endif
  166. }
  167.  
  168. //----------------------------------------------------------------------------------------
  169. //    CDrawPromise::FulfillPromise
  170. //----------------------------------------------------------------------------------------
  171.  
  172. void CDrawPromise::FulfillPromise(Environment *ev, 
  173.                                     ODStorageUnitView *promiseSUView, 
  174.                                     ODPropertyName propertyName, 
  175.                                     ODValueType valueType, 
  176.                                     FW_CCloneInfo* cloneInfo)
  177. {
  178.     FW_ASSERT(FW_PrimitiveStringEqual(propertyName, kODPropContents));
  179.     if (FW_PrimitiveStringEqual(valueType, GetPart(ev)->GetPartKind(ev)))
  180.     {
  181.         // ----- Create an archive object -----
  182.         FW_CStorageUnitSink sink(promiseSUView);
  183.         CDrawWritableStream archive(ev, &sink, cloneInfo);
  184.     
  185.         // ----- Write number of shapes -----
  186.         unsigned long count = fCollection->Count();
  187.         archive << count;
  188.         
  189.         // ----- Write top left offset -----
  190.         archive << fSelectionRect.left;
  191.         archive << fSelectionRect.top;
  192.         
  193.         // ----- Clone the contents of the selection -----
  194.         FW_COrderedCollectionIterator ite(fCollection);
  195.         for (CBaseShape *shape = (CBaseShape*)ite.First(); ite.IsNotComplete(); shape = (CBaseShape*)ite.Next())
  196.         {
  197.             if (shape->IsPromised(GetStorageKind(ev)))
  198.                 FW_WRITE_DYNAMIC_OBJECT(archive, shape, CBaseShape);
  199.         }
  200.     }
  201.     else if (FW_PrimitiveStringEqual(valueType, FW_CPart::gMacPICTDataType))
  202.     {
  203.         FW_PPicture picture;
  204.         
  205.         {
  206.             FW_CPictureContext pc(ev, picture, fSelectionRect.Width(), fSelectionRect.Height());
  207.             
  208.             // ----- Clone the contents of the selection -----
  209.             FW_COrderedCollectionIterator ite(fCollection);
  210.             for (CBaseShape *shape = (CBaseShape*)ite.First(); ite.IsNotComplete(); shape = (CBaseShape*)ite.Next())
  211.             {
  212.                 if (shape->GetShapeType() != kProxyShape)
  213.                 {
  214.                     shape->OffsetShape(ev, -fSelectionRect.left, -fSelectionRect.top);
  215.                     shape->RenderShape(ev, NULL, pc);
  216.                     shape->OffsetShape(ev, fSelectionRect.left, fSelectionRect.top);
  217.                 }
  218.             }
  219.         }
  220.         
  221.         FW_PlatformPict platformPict = picture->GetPlatformPict();
  222.  
  223.         unsigned long pictSize = FW_CMemoryManager::GetSystemHandleSize((FW_PlatformHandle)platformPict);
  224.     
  225.         FW_CAcquireLockedSystemHandle lockedHandle((FW_PlatformHandle)platformPict);
  226.  
  227.         FW_CStorageUnitSink sink(promiseSUView);
  228.         FW_CWritableStream stream(&sink);
  229.         stream.Write(lockedHandle.GetPointer(), pictSize);        
  230.     }
  231. #ifdef FW_DEBUG
  232.     else
  233.         FW_DEBUG_MESSAGE("CDrawDesignator::Externalize - Unknown type");
  234. #endif
  235. }
  236.